<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="Cache-Control" content="no-transform" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=yes" />
		<meta name="csrf_token" id="token" content="{{ csrf_token() }}">
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="{{env('CDN_DOMAIN_NAME')}}/css/pc_login.css"/>
		<link href="{{env('CDN_DOMAIN_NAME')}}/css/commoncss/caution.css" rel="stylesheet">
		<script src="{{env('CDN_DOMAIN_NAME')}}/js/app.js"></script>
	</head>
	<body>
		<div class="login">
			<div class="login_top">
				<p class="login_p radius1 on" style="cursor: default;width:100%;background:#fff;color:rgb(123, 123, 123);border-bottom:1px solid #c1c1c1;">管理员登录</p>
			</div>
			<div class="login_bottom">
				<ul>
					<li class="login_li">
						<div class="login_txt">						
							<input class="login_inp" type="text" autocomplete="off" autocorrect="off" maxlength="11" placeholder="请输入账号(手机号)" name="admin_tel" id="admin_tel" />
							<a href="javascript:;" class="login_a" style="display:none;"><img src="/img/00015.png"/></a>
						</div>
						<div class="login_div">
							<input type="text" maxlength="6" class="enter" name='code1' id="code1" placeholder="请输入验证码" />
							<input type="button" id="send1" class="login_send" onclick="send('/getCode','admin_tel','1')" value="获取验证码" />
						</div>
						<button class="login_btn btn1" onclick="adminLogin()">登录</button>
					</li>
					<li class="login_li">
						<div class="login_txt">
							<input class="login_inp" type="text" maxlength="11" placeholder="请输入账号(手机号)" name="admin_tel" id="user_tel" />
							<a href="javascript:;" class="login_a" style="display:none;"><img src="/img/00015.png"/></a>
						</div>
						<div class="login_div">
							<input type="text" maxlength="6" class="enter" name='code2' id="code2" placeholder="请输入验证码" />
							<input type="button" id="send2" class="login_send" onclick="send('/api/getTelCode','user_tel','2')" value="获取验证码" />
						</div>
						<button class="login_btn btn2" onclick="login()">登录</button>
					</li>
				</ul>
			</div>		
		</div>
		@include('public/caution')
		<div class="police" style="width: 100%; height: 100px; position: absolute; bottom: 0px; left: 0px;">
			<div style="width:350px;margin:0 auto; padding:60px 0; font-size:0.46rem;color:#939393;">
				<a href="javascript:;" style="color:#fff;display:inline-block;height:20px;line-height:20px;float:left;">浙ICP备17055358号-1</a>
				<a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=33010802008920" style="display:inline-block;height:20px;line-height:20px;float:right;">
					<img src="/img/badge.png" style="float:left;">
					<p style="float:left;height:20px;line-height:20px;margin-left:5px;color:#fff; ">浙公网安备 33010802008920号</p>
				</a>
			</div>
		</div>s
	</body>
</html>
<script>
	//叉号显示隐藏及清空
	$(".login_inp").on("input propertychange",function(){  
	     if($(this).val()==""){  
	        $(".login_a").hide(); 		       
	    }else{
	     	$(".login_a").show();		     	
	    }		    
	})	
	$(".login_a").click(function(){
		$(".login_inp").val("");
		$(".login_a").hide();
	})
	/*点击切换*/
//	$(".login_p").click(function(){
//		var index=$(this).index();
//		$(".login_bottom ul").find("li").eq(index).show().siblings().hide();
//		$(this).addClass('on').siblings().removeClass('on')
//		$(this).css({"color":"#fff"}).siblings().css({"color":"#7b7b7b"})
//	});
//	$(".login_p").hover(function(){
//		if($(this).hasClass('on')){
//		}else{
//			$(this).css({"color":"#383838"})
//		}
//	},function(){
//
//		if($(this).hasClass('on')){
//		}else{
//			$(this).css({"color":"#7b7b7b"})
//		}
//	});
	function send(url,id,num) {
		$('#send'+num).css('color','#bcbdbc');
		$('#send'+num).attr('disabled','disabled').css('cursor','not-allowed');
	    var tel = $('#'+id).val();
    	if (!(/^1[3456789]\d{9}$/.test(tel))){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("手机格式不正确");
            $(".oSuccess").show(0).delay(1000).hide(0);
			$('#send'+num).css('color','#000');
			$('#send'+num).removeAttr('disabled').css('cursor','pointer');
            return false;
        }
		$.ajax({
			url:url,
			type:'GET',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
			data:{
			    'user_tel':tel
			},
			dataType:'json',
			success:function (data) {
                if(data.success == true)
                {
                    var n = 60;
					$('#send'+num).css('color','#bcbdbc');
                    var timer = setInterval(function(){
                        n--;
                        $('#send'+num).val(""+n+"s后获取");
                        $('#send'+num).attr('disabled','disabled').css('cursor','not-allowed');

                        if(n==0){
                            clearInterval(timer);
                            $('#send'+num).val("获取验证码");
                            n=60;
                            $('#send'+num).removeAttr('disabled').css('cursor','pointer');
                            $('#send'+num).css('color','#000')
                        }
                    },1000);
                }else {
					$('#send'+num).removeAttr('disabled').css({'cursor':'pointer','color':'#383838'});
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text(data.msg);
                    $(".oSuccess").show(0).delay(1000).hide(0);
                    return false;
				}
            }
		})
    }
	/*管理员登录*/
	function adminLogin() {
        var admin_tel = $('#admin_tel').val();
        var code = $('#code1').val();
		if(admin_tel == ''){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("请填写手机号");
            $(".oSuccess").show(0).delay(1000).hide(0);
			return false;
		}else if(!(/^1[3456789]\d{9}$/.test(admin_tel))){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("手机格式不正确");
            $(".oSuccess").show(0).delay(1000).hide(0);
            return false;
		}else if(code == ''){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("请获取验证码并填写");
            $(".oSuccess").show(0).delay(1000).hide(0);
            return false;
		}
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            type: 'post',
            url: '/adminLoginIn',
            data: {
                'admin_tel':admin_tel,
				'code':code
            },
			dataType:'json',
            success: function (data) {
				if(data.success == true){
					location.href='/backstage/home';
				}else{
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text(data.msg);
                    $(".oSuccess").show(0).delay(1000).hide(0);
				}

            }
        })
    }
    /*客户登录*/
    function login() {
        var user_tel = $('#user_tel').val();
        var code = $('#code2').val();
        if(user_tel == ''){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("请填写手机号");
            $(".oSuccess").show(0).delay(1000).hide(0);
            return false;
        }else if(!(/^1[3456789]\d{9}$/.test(user_tel))){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("手机格式不正确");
            $(".oSuccess").show(0).delay(1000).hide(0);
            return false;
        }else if(code == ''){
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text("请获取验证码并填写");
            $(".oSuccess").show(0).delay(1000).hide(0);
            return false;
        }
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            type: 'post',
            url: '/userLoginIn',
            data: {
                'user_tel':user_tel,
                'code':code
            },
            dataType:'json',
            success: function (data) {
                if(data.success == true){
					if(data.msg == '0'){   //买家

                        window.location.href = "/dealer";
                    }else if(data.msg == '2'){
                        window.location.href = "/dealer/qualityIndex";
					}
                }else{
                    if(data.msg == '-1'){
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text("验证码不正确");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        return false;
                    }else if(data.msg == '-2')
                    {
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text("无注册用户");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        return false;
                    }
                }
            }
        })
    }
    /*回车登录*/
    $('.enter').bind('keydown',function(event){
        if(event.keyCode == "13") {
            var admin_tel = $('#admin_tel').val();
            var code = $('#code1').val();
            if(admin_tel == ''){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请填写手机号");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }else if(!(/^1[3456789]\d{9}$/.test(admin_tel))){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("手机格式不正确");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }else if(code == ''){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请获取验证码并填写");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type: 'post',
                url: '/adminLoginIn',
                data: {
                    'admin_tel':admin_tel,
                    'code':code
                },
                dataType:'json',
                success: function (data) {
                    if(data.success == true){
                        location.href='/backstage/home';
                    }else{
                        alert(data.msg);
                    }

                }
            })
        }
    });
</script>
